#if !defined(__APP_BUFFER_H)
#define __APP_BUFFER_H
#include <pthread.h>
//读/写缓冲区
typedef struct 
{
    unsigned char *ptr;//容器内存指针
    int size;//容器大小
    int len;//存储数据的长度
} SubBuffer;

typedef struct 
{
    SubBuffer *sub_buffers[2];//包含读写的缓冲区
    int read_index;//读缓冲区的索引
    int write_index;//写缓冲区的索引
    pthread_mutex_t read_lock;
    pthread_mutex_t write_lock;
} Buffer;

//初始化缓冲区
Buffer *app_buffer_Init(int size);

//释放缓冲区
void app_buffer_free(Buffer *buffer);

//向缓冲区写入数据
int app_buffer_write(Buffer *buffer,char *data,int len);

//从缓冲区读取数据
int app_buffer_read(Buffer *buffer,char *data_buf,int buf_size);
#endif // __APP_BUFFER_H
